package com.spring.service.impl;

import com.spring.service.MessageService;
import com.spring.until.KeyUtil;
import com.spring.until.SMSUtil;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class MessageServiceImpl implements MessageService {
    @Override
    public int sendMessage(HttpServletRequest request) {
        String phone = request.getParameter("phone") ;
        String code = KeyUtil.keyUtils() ;
        boolean ok = SMSUtil.sendSMS(phone,code) ;
        if(ok){
            JSONObject json = new JSONObject() ;
            json.put("createTime",System.currentTimeMillis());
            json.put("code",code) ;
            request.getSession().setAttribute("SMSCode",json);
            return 1 ;
        }
        return 0 ;
    }
}
